<template>
  <base-window
    size="medium"
    width="820px"
    class="department-user-modal"
    :class-name="`base-contact department-user-modal ${!isMulti && 'department-user-modal-not-multi'}`"
    ref="BaseWindowComponent"
    :options="options"
    :title="title"
    :top="top"
    :unique="unique"
    :show.sync="show" 
    @closed="$emit('destroy')"
    @cancel="$emit('cancel')"
  >
    <div class="bc-dept-wrap">
      <div class="bc-dept" v-if="depts.length > 0 && departShow">
        <base-tree-dept
          expand
          :data="depts" 
          :node-render="nodeRender"
          :selected="[selectedDept]" 
          :show-checkbox="allowCheckDept"
          @node-selected="initDeptUser" 
          @node-check="chooseDept" 
        />
      </div>
      
      <div class="bc-user">
        <div class="bc-search">
          <label class="bc-search-inner">
            <i class="iconfont icon-search"></i>
            <input ref="Input" type="search" :placeholder="$t('common.placeholder.searchStaff')" :value="params.keyword" @input="inputKeyword" maxlength="50" autofocus>
          </label>
          <!-- 筛选标签 -->
          <screening-user :states="states" @tagsChange="tagsChange"></screening-user>
        </div>
        
        <div class="bc-user-panel" v-loadmore="loadmoreOptions">
          <p class="bc-contact-search-tip" v-if="mode == 'search' && !loading">{{ $t('common.base.tip.totalSearchResult2', {data1: userPage.total || 0}) }}</p>
          
          <contact-user-item 
            v-for="user in userPage.list" 
            :key="user.userId" 
            :user="user" @toggle="chooseUser" 
            :show-user-state="showUserState" 
            :state-color="stateColor"
            :show-location="showLocation"
          />
          
          <div class="bc-contact-loading" v-if="loading">{{$t('common.base.waiting2')}}</div>
          <div v-if="userPage.total == 0 && !loading && mode == 'choose'" class="bc-contact-empty">
            <img :src="noAuthImage" />
            <p>{{$t('common.base.noMember')}}</p>
          </div>
        </div>
      </div>
      
      <div class="bc-chosen" v-if="isMulti">
        <template v-if="allowCheckDept && chosenDept.length > 0&&!allowCheckDeptShowUser">
          <h4>{{$t('common.department.selectedDepartment')}}</h4>
          <div 
            class="bc-chosen-user" 
            v-for="dept in chosenDept" :key="dept.id">
            <span>
              <open-data v-if="isOpenData && dept.dingId" type="departmentName" :openid="dept.dingId" />
              <span v-else>
                {{ dept.name }}
              </span>
            </span>
            <i v-if="canDel" class="iconfont icon-fe-close" @click="chooseDept({node: dept, value: false})"></i>
          </div>
        </template>
        <template v-if="chosen.length > 0">
          <h4 v-if="allowCheckDept">{{ $t('common.department.selectedMember') }}</h4>
          <div class="bc-chosen-user" v-for="user in chosen" :key="user.userId">
            <div class="bc-chosen-user-head" :style="{backgroundImage: 'url(' + head(user) + ')'}"></div>
            <template v-if="isOpenData">
              <open-data type="userName" :openid="user.staffId"></open-data>
            </template>
            <template v-else>
              <span>{{user.displayName}}</span>
            </template>
            <i class="iconfont icon-fe-close" @click="removeUser(user)"></i>
          </div>
        </template>
      </div>
    </div>
    <div slot="footer" class="bc-contact-footer" v-if="isMulti">
      <span class="bc-contact-chosen-count">{{summary}}</span>
      <button type="button" class="bc-contact-cancel" @click="show = false">{{$t('common.base.close')}}</button>
      <button type="button" class="bc-contact-choose" @click="post">{{$t('common.base.confirm')}}</button>
    </div>
  </base-window>
</template> 

<script>
import { t } from '@src/locales'
import { isAllotByDepartment, isOpenData } from '@src/util/platform'
import { getOssUrl } from '@src/util/assets'
/* eslint-disable */
import _ from 'lodash';
import http from '@src/util/http';
import { getRootWindow } from '@src/util/dom'
import Page from '@model/Page';
import {alert as FeAlert} from '@src/util/platform';

import ContactUserItem from './ContactUserItem.vue';
const DefaultHead = getOssUrl('/avatar.png')

import { teamNameConversion } from '@src/util/conversionFunctionUtil.ts'

// Api
import { getDeptUserList, getTagTeamLeaders } from '@src/api/DeptHomeApi';
import { checkUser } from '@src/api/serviceProviderApi';

// conmponent
import ScreeningUser from './ScreeningUser.vue'
import { isEmpty, isArray } from '@src/util/type';

export default {
  name: 'base-contact-dept-user',
  props: {
    /** 
     * 最大选择人数，
     * 1 -- 单选
     * > 1 -- 多选
     * <= 0 -- 不限制选择人数
     */
    max: {
      type: Number,
      default: 0
    },
    selectedUser: {
      type: Array,
      default: () => []
    },
    title: {
      type: String,
      default: t('common.placeholder.selectMember')
    },
    // 是否显示任务统计
    showTaskCount: {
      type: Boolean,
      default: false
    },
    // 是否显示用户工作状态
    showUserState: {
      type: Boolean,
      default: false
    },
    action: { // 用户数据请求地址
      type: String,
      default: '/security/tag/userList'
    },
    lat: {
      type: String,
      default: ''
    },
    lng: {
      type: String,
      default: ''
    },
    // 是否显示定位信息
    showLocation: { 
      type: Boolean,
      default: false
    },
    // 是否允许选中部门
    showDeptCheckbox: {
      type: Boolean,
      default: false
    },
    CheckDeptshowUser: {
      type: Boolean,
      default: false
    },
    selectedDepts: {
      type: Array,
      default: () => ([])
    },
    /* 是否查询 开始降低组织架构的选项 */
    seeAllOrg: {
      type: Boolean,
      default: false
    },
    departShow: {
      type: Boolean,
      default: true
    },
    // 是否显示离职人员
    showDeleteUser: {
      type: Boolean,
      default: false
    },
    top: {
      type: Boolean,
      default: true
    },
    unique: {
      type: Boolean,
      default: true
    },
    options: {
      type: Object,
      default: () => ({})
    },
    from: {
      type: String,
      default: ''
    },
    // 服务商 控制左边树 【0组织架构】 【1服务商】 【''全部】 默认和之前逻辑一样
    typeServiceProvider: {
      type: Number | String,
      default: ''
    },
    // 是否验证被选中的人是不是主管
    isJudge: {
      type: String,
      default: ''
    },
    // true为过滤没有角色的用户，false 为不校验角色
    haveRole: {
      type: Boolean,
      default: false
    },
    // 是否是企微端用户引导
    isUserGuide: {
      type: Boolean,
      default: false
    },
    // 是否可以删除选中的人
    canDel: {
      type: Boolean,
      default: true
    },
    // 是否是日历模块
    isCalendar: {
      type: Boolean,
      default: false
    },
    // 左侧树请求的接口
    calendarAction: { // 用户数据请求地址
      type: String,
      default: ''
    },
    calendarSeeAllOrg: {
      type: Boolean,
      default: false
    },
    //是否需要邮箱字段
    isNeedEmail:{
      type:Boolean,
      default:false
    },
    // 为true只显示tag表数据 勾选按企微或者钉钉组织架构无效
    isShowTag: {
      type: Boolean,
      default: false
    },
    // 分配角色页面 添加成员 showNoRole为true
    showNoRole: {
      type: Boolean,
      default: false
    },
    authKey:{
      type: [String, null],
      default: null
    }
  },
  data(){
    let data = {
      isOpenData,
      mode: 'choose',
      show: false,
      loading: true,
      loadmoreOptions: {
        disabled: false,
        callback: this.loadmore
      },

      depts: [], // 部门
      deptUserCount: {},
      selectedDept: {}, // 选中的部门
      chosenDept: this.selectedDepts.map(dept => {
        return {
          id: dept.id,
          name: dept.name || dept.tagName
        }
      }),
      // 已选择的人
      chosen: this.selectedUser.map(item => {
        return {
          userId: item.userId,
          displayName: item.displayName,
          staffId: item.staffId,
          head: item.head || '',
          selected: true
        }
      }), 

      params: {
        keyword: '', // 搜索关键词
        // deptId: '',
        // departmentId: '',
        pageNum: 1,
        pageSize: 50,
        showNoRole: this.showNoRole
      }, // 参数
      userPage: new Page(),

      stateColor: {}, //用户工作状态颜色
      isSeeAllOrg: false, /** 是否 只可见本团队成员 */
      states: {}, // 工作状态
      tagList:[], // 标签数据

      stateParams: [],
      labelIdsParams: [],
      // 当前页面的window数据
      pageWindowData:null,
      noAuthImage:getOssUrl('/no_data.png')
    }

    return data
  },
  computed: {
    mainTagId(){
      // 组织架构主tag
      return this.depts[0].id 
    },
    isDingtalk(){
      // 判断是否钉钉端选择通讯录
      return isAllotByDepartment()
    },
    btnText(){
      return this.max > 0 ? `(${this.chosen.length}/${this.max})` : "";
    },
    // 是否多选
    isMulti(){
      return this.max != 1;
    },
    // 是否允许添加用户
    allowAddUser(){
      if (this.max <= 0) return true;
      return this.chosen.length < this.max;
    },
    // 当前已选概览
    summary(){
      let text = t('common.department.currSelectedPeople', { length: this.chosen.length });
      if(this.allowCheckDept) {
        text += `,${t('common.department.departCount', { length: this.chosenDept.length })}`;
      }
      return text;
    },
    
     // 是否允许选中部门显示人
    allowCheckDeptShowUser(){
      return this.allowCheckDept && this.CheckDeptshowUser;
    },
    // 是否允许选中部门
    allowCheckDept(){
      return this.isMulti && this.showDeptCheckbox;
    },
    chosenDeptIdMap() {
      let idMap = {};
      
      this.chosenDept.forEach(dept => {
        if (dept?.id) {
          idMap[dept.id] = dept;
        }
      })
      
      return idMap;
    }
  },
  methods: {
    async post(){
      // 判断被选中的人是否可以被选择
      const userIds = this.chosen.map(x=>x.userId);

      if(this.chosen.length > 0 && this.isJudge === 'dept'){
        const res = await getTagTeamLeaders({
          userIds,
          type: 0
        });
        if(res.status !== 0) return alert(res.message);
        
        if(res.data.length > 0) {
          return FeAlert(t('common.department.addErrorTip', { accounts:  isOpenData ? '' : `，${t('common.department.addErrorTip')}${res.data.join('，')}`}));
        }
        
      }else if(this.chosen.length > 0 && this.isJudge === 'service'){
        const res = await checkUser({
          userIds,
          type: 0
        });
        if(res.status !== 0) return FeAlert(res.message);
      }

      let data = {};
      let users = this.chosen.map(item => {
        let temp = {
          userId: item.userId,
          displayName: item.displayName,
          staffId: item.staffId,
          head: item.head || ''
        };
        if(this.isNeedEmail&&item.email) temp.email =item.email
        return temp
      });
      data.users = users;

      if(this.allowCheckDept){
        let depts = this.chosenDept.map(item => {
          return {
            dingId: item.dingId,
            id: item.id,
            name: item.name
          }
        }) 
        data.depts = depts;
      }
      
      this.show = false;
      this.$emit('input', data);
    },
    inputKeyword(event){
      this.params.keyword = event.target.value;
      this.search();
    },
    /** 搜索人员 */
    search: _.debounce(function(){
      if(!this.params.keyword){ // 空值  显示团队
        this.mode = 'choose';
        this.initDeptUser(this.selectedDept);
        return;
      }
      
      this.searchUser();
    }, 500),
    /** 选择人员 */
    chooseUser(user){
      if(!user) return;
      //是否选择带有邮箱的用户
      if(this.isNeedEmail&&!user.email){
        FeAlert(t('common.department.userUnbindEmail'))
        return
      }
      // 单选则直接返回
      if(!this.isMulti) {
        this.show = false;
        this.$emit('input', {
          users: [{
            userId: user.userId,
            displayName: user.displayName,
            staffId: user.staffId,
            head: user.head || ''
          }]
        })
        return;
      }
      
      user.seleced ? this.removeUser(user) : this.addUser(user);
    },
    /** 添加人员 */
    addUser(user){
      if(!this.allowAddUser) return FeAlert(t('common.department.limitChoicePeople', { limit: this.max }));
      
      user.selected = true;
      
      var index = -1;
      var len = this.chosen.length;
      for(var i = 0; i < len;i++){
        if(user.userId == this.chosen[i].userId){
          index = i;
          break;
        }
      }
      index == -1 && this.chosen.push(user);
    },
    /** 移除选择的人员 */
    removeUser(user){
      user.selected = false;

      var index = -1;
      var len = this.chosen.length;
      for(var i = 0; i < len;i++){
        if(this.chosen[i].userId == user.userId){
          index = i;
          break;
        }
      }
      index >= 0 && this.chosen.splice(index,1);
    },
    /** 搜索用户 */
    async searchUser(isDel = true){
      try {
        this.mode = 'search';
        this.loading = true;
        this.userPage.list = [];

        if(isDel){
          this.params.deptId = this.selectedDept.parentId ? this.selectedDept.id : 'root';
          this.params.tagId = this.selectedDept.parentId ? this.selectedDept.id : '';
          this.params.pageNum = 1;  
        }

        if(this.showLocation){
          this.params.lat = this.lat;
          this.params.lng = this.lng;
        }
        this.params.seeAllOrg = this.isSeeAllOrg;
        // 可显示离职人员
        const { id, name } = this.selectedDept;
        this.params.showDeleteUser = (id == 'root' && name == t('common.department.separatingEmployee')) ? 1 : (this.showDeleteUser ? 2 : 0);

        let userPage = await this.fetchUser(this.params);
        this.userPage.merge(Page.as(userPage));
      } catch (error) {
        console.error(error)
      }

      this.loading = false
      this.loadmoreOptions.disabled = !this.userPage.hasNextPage;
    },
    /** 选中一个部门 */
    async initDeptUser(dept){
      try {
        this.mode = 'choose';
        this.selectedDept = dept;
        this.userPage.list = [];
        this.loading = true;
        
        // 查询用户
        this.params.keyword = '';
        this.params.tagId = !this.selectedDept.parentId ? '' : this.selectedDept.id;
        // start 兼容钉钉端 
        this.params.deptId = this.selectedDept.id;
        this.params.departmentId = this.selectedDept.id;
        // end 
        this.params.pageNum = 1;

        if(this.showLocation){
          this.params.lat = this.lat;
          this.params.lng = this.lng;
        }
        this.params.seeAllOrg = this.isSeeAllOrg;
        // true为过滤没有角色的用户，false 为不校验角色
        this.params.haveRole = this.haveRole;
        // 离职人员
        dept.name = dept.name || dept.tagName
        this.params.showDeleteUser = (dept.id == 'root' && dept.name == t('common.department.separatingEmployee')) ? 1 : 0;
        // fix:9002
        if(dept.id == 'root' && dept.name == t('common.department.separatingEmployee')) {
          this.params.tagId = 'root';
        }

        // 添加type值 展示服务商和组织架构成员
        this.params.type = dept.parentId ? null : dept.type;
        if(this.isCalendar) {
          this.params.type = dept.parentId ? null : dept.serviceType;
        }
        let userPage = await this.fetchUser(this.params);

        this.userPage.merge(Page.as(userPage));
        let have = this.chosenDept.findIndex(item=>item.id === dept.id);
        if(this.allowCheckDeptShowUser&&this.userPage.list.length&&have>-1){
          this.userPage.list.forEach(item=>{
            this.chooseUser(item)
          })
        }
      } catch (error) {
        console.error(error)
      }

      this.loading = false;
      this.loadmoreOptions.disabled = !this.userPage.hasNextPage;
    },
    /** 选择部门 */
   async chooseDept(event){
      let {node, value} = event;
      this.toggleDeptCheckStatus(node, value);
      this.chosenDept = this.filterChosenDept(this.depts).map(teamNameConversion)
      if(this.allowCheckDeptShowUser){
        for(let i of this.chosenDept){
          await this.initDeptUser(i)
        }
        
      }
    },
    /** 切换该部门及子部门选中状态 */
    toggleDeptCheckStatus(dept, value){
      this.$set(dept, 'isChecked', value);

      let subDepts = dept.children || [];
      if(subDepts.length > 0){
        subDepts.forEach(item => this.toggleDeptCheckStatus(item, value))
      }
    },
    // 筛选所有被选中的部门
    filterChosenDept(depts){
      if(!Array.isArray(depts) || depts.length == 0) return [];

      let chosen = [];
      for(let i = 0; i < depts.length; i++){
        let dept = depts[i];
        if(dept.isChecked) chosen.push(dept);
        if(dept.children) chosen = chosen.concat(this.filterChosenDept(dept.children))
      }
      return chosen;
    },
    async loadmore(){
      this.loadmoreOptions.disabled = true;
      this.loading = true;

      try {
        this.params.pageNum += 1;
        this.params.seeAllOrg = this.isSeeAllOrg;
      
        let userPage = await this.fetchUser(this.params);
        this.userPage.merge(Page.as(userPage));
      } catch (error) {
        console.error(error)
      }

      this.loading = false;
      this.loadmoreOptions.disabled = !this.userPage.hasNextPage;
    },
    /** 抓取用户数据 */
    fetchUser(params = {}) {
      if(this.isUserGuide) return this.fetchGuideUser()
      if((this.isDingtalk || (this.isCalendar && !this.calendarSeeAllOrg)) && !this.isShowTag) return this.fetchDingtalkUser()

      if (this.from) {
        this.params.isDelete = null
      }
      
      const taskId = this.pageWindowData?.task?.id
      const taskState = this.pageWindowData?.task?.state
      const allotByExclusiveTag = this.pageWindowData?.taskConfig?.allotByExclusiveTag
      if(taskId && allotByExclusiveTag && taskState === "created"){
        params.taskId = taskId
      }
      return http.post(this.action, params, false).then(page => {
        // 合并数据
        let rows = page.list || [];

        for(let i = 0;i < rows.length; i++){
          let user = rows[i];

          let index = -1;
          for(let j = 0; j < this.chosen.length; j++){
            if(user.userId == this.chosen[j].userId){
              index = j;
              break;
            }
          }

          if(index >= 0){// 存在相同数据 则替换原数据
            user.selected = true;
            this.$set(this.chosen, index, user);
          }else{
            user.selected = false;
          }
        }
        return page;
      })
        .catch(err => console.error('err', err));
    },
    fetchGuideUser() {
      let params = this.params;
      params.useStateBlackList = localStorage.getItem('useStateBlackList') || 0; 
      return http.get('/security/department/user/all', params).then(userPage => {
        
        return userPage;
      })
        .catch(err => console.error('err', err))
    },
     /** 抓取钉钉端用户数据 */
    fetchDingtalkUser(){      
      let params = this.params;
      const taskId = this.pageWindowData?.task?.id
      const taskState = this.pageWindowData?.task?.state
      const allotByExclusiveTag = this.pageWindowData?.taskConfig?.allotByExclusiveTag
      if(taskId && allotByExclusiveTag && taskState === "created"){
        params.taskId = taskId
      }
      params.useStateBlackList = localStorage.getItem('useStateBlackList') || 0; 
      return http.get('/security/department/user', params).then(userPage => {

        return userPage;
      })
        .catch(err => console.error('err', err))
    },
    /** 抓取部门数据 */
    fetchDept(){
      if((this.isDingtalk || this.isUserGuide) && !this.isShowTag) return this.fetchDingtalkDept();
      let params = {};
      params.seeAllOrg = this.isSeeAllOrg;
      params.showDeleteUser = this.showDeleteUser ? 1 : 0;
      params.type = this.typeServiceProvider;
      
      if(this.authKey){
        params['authKey'] = this.authKey;
      }

      return http.post('/security/tag/tree', params).then(result => {
        let depts = (result && result.list) || [];
        return depts;
      })
        .catch(err => console.error('err', err));
    },
    /** 抓取钉钉部门数据 */
    fetchDingtalkDept(){
      let params = {};
      params.seeAllOrg = this.isSeeAllOrg;
      params.showDeleteUser = this.showDeleteUser ? 1 : 0;
      return http.get('/security/department/tree', params).then(result => {
        if(result.status == 1) return [];

        let depts = result.data || [];
        // 钉钉端数据处理
        depts =  JSON.parse(JSON.stringify(depts).replace(/name/g,'tagName').replace(/subDepartments/g,'children'));
        if(this.isUserGuide) return depts
        let index = -1;

        for(var i = 0; i < depts.length; i++){
          if(depts[i].tagName == t('common.department.individuallyAuthorizedPerson')){
            index = i;
            break;
          }
        }

        // 将单独授权人员放在最后
        if(index >= 0){
          let arr = depts.splice(index,1);
          depts.push(arr[0]); 
        }
        
        return depts;
      })
        .catch(err => console.error('err', err));
    },
    fetchDeptCount(){
      return http.get('/security/department/depUserCount')
    },
    // 日历选人
    calendarFetchDept(){
      return http.get(this.calendarAction).then(result => {
        let depts = (result && result.data) || [];
        return depts;
      })
        .catch(err => console.error('err', err));
    },
    /** 初始化 */
    initialize(){
      this.show = true;
      this.initializeDept();
      if(this.showUserState) this.initializeStateColor();
    },
    /** 初始化部门数据 */
    async initializeDept(){
      this.isSeeAllOrg = false;
      try {
        /* 如果开启 查询按组织架构选项 */
        if (this.seeAllOrg) {
          let result = await this.getSeeAllOrg();
          this.isSeeAllOrg = result.data;
        }
        let result = await this.getSeeAllOrg();
        this.isSeeAllOrg = result.data;
      } catch (error) {
        console.log('error: ', error);
        this.isSeeAllOrg = false;
      }

      let subtask = [];
      if(this.isCalendar){
        subtask.push(this.calendarFetchDept())
      }else {
        subtask.push(this.fetchDept());
        if(this.allowCheckDept) subtask.push(this.fetchDeptCount())
      }

      Promise.all(subtask)
        .then(result => {
          let depts = result[0] || [];
          
          if(this.allowCheckDept){
            let deptUserCount = result[1] || {};
            this.deptUserCount = deptUserCount.data || {};
          }
          this.depts = depts
          this.initChosenDept(this.depts);
          this.initDeptUser(this.depts[0]); // 默认选中第一个
        })
        .catch(err => console.error(err))
    },
    /** 初始化选中的部门 */
    initChosenDept (depts) {
      depts.forEach(dept => {
        
        if(this.chosenDeptIdMap?.[dept?.id]) {
          this.toggleDeptCheckStatus(dept, true)
          return 
        }
        
        if (isArray(dept?.children) && !isEmpty(dept.children)) {
          this.initChosenDept(dept.children)
        }
      })
    },
    /** 初始化工作状态的颜色 */
    initializeStateColor(){
      http.get('/setting/getStateColorMap')
        .then(res => this.stateColor = _.assign({}, this.stateColor,res || {}))
        .catch(err => console.error(err))
    },
    /** 获取用户头像 */
    head(user){
      return user.head || DefaultHead;
    },
    nodeRender(h, node){
      const { source, tagName, weChatDeptId, dingId } = node
      let content;
      if(this.isOpenData && dingId) {
        content = (<span><open-data type="departmentName" openid={dingId}></open-data></span>) 
      } else {
        content = (<span>{tagName}</span>)
      }
      if(!this.allowCheckDept) return content
      
      // let count = this.deptUserCount[node.id] || 0
      let count =  0
      if(count <= 0) return content;
      if(this.isOpenData && dingId) {
        content = (<span></span>) 
        return (
          <div class="bc-dept-node-wrap">
            <span class="bc-dept-node-name"><open-data type="departmentName" openid={dingId}></open-data></span>
            <span class="bc-dept-node-count">{count}</span>
          </div>
        )
      } 
      return (
        <div class="bc-dept-node-wrap">
          <span class="bc-dept-node-name">{node.tagName}</span>
          <span class="bc-dept-node-count">{count}</span>
        </div>
      )
    },
    /* 查询是否开启 降低组织架构的开关 */
    getSeeAllOrg() {
      return http.post('/setting/user/getSeeAllOrg').then(result => { 
        return result
      })
    },
    closeOtherUserWindow() {
      try {
        const baseWindowComponent = this.$refs.BaseWindowComponent || {}
        const windowIds = baseWindowComponent?.getBaseWindowIds()
        const userWindowIds = windowIds.filter(id => id.indexOf('base-user') >= 0)

        userWindowIds.forEach(id => {
          baseWindowComponent?.closeWindow(id)
        })

      } catch (error) {
        console.warn('closeOtherUserWindow ~ error', error)
      }
    },
    // 标签选择的变化
    tagsChange(e){
      this.params.stateStr = e.tags.length > 0 ? e.tags.join() : '';
      this.params.labelIdsStr = e.label.length > 0 ? e.label.join() : '';

      this.searchUser(false);
    }
  },
  mounted(){
    try {
      let rootWindow = getRootWindow(window);
      this.pageWindowData = JSON.parse(rootWindow?._init || '{}')
      this.states = this.pageWindowData.userStateMap || {};
    } catch (error) {
      console.log(error);
    }
    this.initialize()
    this.closeOtherUserWindow()
  },
  components: {
    [ContactUserItem.name]: ContactUserItem,
    [ScreeningUser.name]: ScreeningUser
  }
}
</script>

<style lang="scss">
  @import './department.scss';
</style>
